package com.sky.controller.admin;

import com.sky.dto.OrdersCancelDTO;
import com.sky.dto.OrdersConfirmDTO;
import com.sky.dto.OrdersPageQueryDTO;
import com.sky.dto.OrdersRejectionDTO;
import com.sky.result.PageResult;
import com.sky.result.Result;
import com.sky.service.OrderService;
import com.sky.vo.OrderStatisticsVO;
import com.sky.vo.OrderSubmitVO;
import com.sky.vo.OrderVO;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.core.annotation.Order;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@Slf4j
@RequestMapping("/admin/order")
@Api(tags = "订单管理接口")
public class OrderContoller {
    @Autowired
    OrderService orderService;

    /*
    查询订单
     */
    @ApiOperation("订单查询接口")
    @GetMapping("/conditionSearch")
    public Result<PageResult> pageQuery(OrdersPageQueryDTO ordersPageQueryDTO) {
        log.info("分页查询的参数为{}", ordersPageQueryDTO);
        PageResult pageResult = orderService.pageQuery(ordersPageQueryDTO);
        return Result.success(pageResult);

    }
    @ApiOperation("订单数据统计接口")
    @GetMapping("/statistics")
    public Result<OrderStatisticsVO> statistics() {
        log.info("数据统计{}");
        OrderStatisticsVO orderStatisticsVO = orderService.statistics();
        return Result.success(orderStatisticsVO);
    }
    @ApiOperation("派单接口")
    @PutMapping("delivery/{id}")
    public Result deliver(@PathVariable Long id) {
        log.info("派送订单{}", id);
        orderService.delivery(id);
        return Result.success();
    }
    @ApiOperation("接单接口")
    @PutMapping("/confirm")
    public Result confirm(@RequestBody OrdersConfirmDTO ordersConfirmDTO) {
        log.info("接单{}", ordersConfirmDTO.getId());
        orderService.confirm(ordersConfirmDTO.getId());
        return Result.success();
    }

    /*
    取消订单
     */
    @ApiOperation("取消订单接口")
    @PutMapping("/cancel")
    public Result cancel(@RequestBody OrdersCancelDTO ordersCancelDTO) {
        log.info("取消的订单号和取消的原因{}", ordersCancelDTO);
        orderService.cancel(ordersCancelDTO);
        return Result.success();
    }

    /*
取消订单
 */
    @ApiOperation("拒绝订单接口")
    @PutMapping("/rejection")
    public Result rejection(@RequestBody OrdersRejectionDTO ordersRejectionDTO) {
        log.info("拒单的订单号和拒单的原因{}", ordersRejectionDTO);
        orderService.rejection(ordersRejectionDTO);
        return Result.success();
    }
    @ApiOperation("订单完成接口")
    @PutMapping("/complete/{id}")
    public Result complete(@PathVariable Long id) {
        log.info("完成的订单号{}", id);
        orderService.complete(id);
        return Result.success();
    }
    @ApiOperation("订单详细接口")
    @GetMapping("/details/{id}")
    public Result<OrderVO> details(@PathVariable Long id) {
        log.info("查询详细的订单号{}", id);
        OrderVO orderVO = orderService.details(id);
        return Result.success(orderVO);
    }

}
